<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.3.5 - src/ldebug.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - ldebug.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.3.5</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">301</td>
            <td class="headerCovTableEntry">379</td>
            <td class="headerCovTableEntryMed">79.4 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:17</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: ldebug.c,v 2.121.1.2 2017/07/10 17:21:50 roberto Exp $
<span class="lineNum">       3 </span>            : ** Debug Interface
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #define ldebug_c
<span class="lineNum">       8 </span>            : #define LUA_CORE
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #include &quot;lprefix.h&quot;
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #include &lt;stdarg.h&gt;
<span class="lineNum">      14 </span>            : #include &lt;stddef.h&gt;
<span class="lineNum">      15 </span>            : #include &lt;string.h&gt;
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      18 </span>            : 
<span class="lineNum">      19 </span>            : #include &quot;lapi.h&quot;
<span class="lineNum">      20 </span>            : #include &quot;lcode.h&quot;
<span class="lineNum">      21 </span>            : #include &quot;ldebug.h&quot;
<span class="lineNum">      22 </span>            : #include &quot;ldo.h&quot;
<span class="lineNum">      23 </span>            : #include &quot;lfunc.h&quot;
<span class="lineNum">      24 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">      25 </span>            : #include &quot;lopcodes.h&quot;
<span class="lineNum">      26 </span>            : #include &quot;lstate.h&quot;
<span class="lineNum">      27 </span>            : #include &quot;lstring.h&quot;
<span class="lineNum">      28 </span>            : #include &quot;ltable.h&quot;
<span class="lineNum">      29 </span>            : #include &quot;ltm.h&quot;
<span class="lineNum">      30 </span>            : #include &quot;lvm.h&quot;
<span class="lineNum">      31 </span>            : 
<span class="lineNum">      32 </span>            : 
<span class="lineNum">      33 </span>            : 
<span class="lineNum">      34 </span>            : #define noLuaClosure(f)         ((f) == NULL || (f)-&gt;c.tt == LUA_TCCL)
<span class="lineNum">      35 </span>            : 
<span class="lineNum">      36 </span>            : 
<span class="lineNum">      37 </span>            : /* Active Lua function (given call info) */
<span class="lineNum">      38 </span>            : #define ci_func(ci)             (clLvalue((ci)-&gt;func))
<span class="lineNum">      39 </span>            : 
<span class="lineNum">      40 </span>            : 
<span class="lineNum">      41 </span>            : static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
<span class="lineNum">      42 </span>            :                                     const char **name);
<span class="lineNum">      43 </span>            : 
<span class="lineNum">      44 </span>            : 
<span class="lineNum">      45 </span><span class="lineCov">        573 : static int currentpc (CallInfo *ci) {</span>
<span class="lineNum">      46 </span>            :   lua_assert(isLua(ci));
<span class="lineNum">      47 </span><span class="lineCov">        573 :   return pcRel(ci-&gt;u.l.savedpc, ci_func(ci)-&gt;p);</span>
<span class="lineNum">      48 </span>            : }
<span class="lineNum">      49 </span>            : 
<span class="lineNum">      50 </span>            : 
<span class="lineNum">      51 </span><span class="lineCov">        398 : static int currentline (CallInfo *ci) {</span>
<span class="lineNum">      52 </span><span class="lineCov">        398 :   return getfuncline(ci_func(ci)-&gt;p, currentpc(ci));</span>
<span class="lineNum">      53 </span>            : }
<span class="lineNum">      54 </span>            : 
<span class="lineNum">      55 </span>            : 
<span class="lineNum">      56 </span>            : /*
<span class="lineNum">      57 </span>            : ** If function yielded, its 'func' can be in the 'extra' field. The
<span class="lineNum">      58 </span>            : ** next function restores 'func' to its correct value for debugging
<span class="lineNum">      59 </span>            : ** purposes. (It exchanges 'func' and 'extra'; so, when called again,
<span class="lineNum">      60 </span>            : ** after debugging, it also &quot;re-restores&quot; ** 'func' to its altered value.
<span class="lineNum">      61 </span>            : */
<span class="lineNum">      62 </span><span class="lineCov">        556 : static void swapextra (lua_State *L) {</span>
<span class="lineNum">      63 </span><span class="lineCov">        556 :   if (L-&gt;status == LUA_YIELD) {</span>
<span class="lineNum">      64 </span><span class="lineNoCov">          0 :     CallInfo *ci = L-&gt;ci;  /* get function that yielded */</span>
<span class="lineNum">      65 </span><span class="lineNoCov">          0 :     StkId temp = ci-&gt;func;  /* exchange its 'func' and 'extra' values */</span>
<span class="lineNum">      66 </span><span class="lineNoCov">          0 :     ci-&gt;func = restorestack(L, ci-&gt;extra);</span>
<span class="lineNum">      67 </span><span class="lineNoCov">          0 :     ci-&gt;extra = savestack(L, temp);</span>
<span class="lineNum">      68 </span>            :   }
<span class="lineNum">      69 </span><span class="lineCov">        556 : }</span>
<span class="lineNum">      70 </span>            : 
<span class="lineNum">      71 </span>            : 
<span class="lineNum">      72 </span>            : /*
<span class="lineNum">      73 </span>            : ** This function can be called asynchronously (e.g. during a signal).
<span class="lineNum">      74 </span>            : ** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by
<span class="lineNum">      75 </span>            : ** 'resethookcount') are for debug only, and it is no problem if they
<span class="lineNum">      76 </span>            : ** get arbitrary values (causes at most one wrong hook call). 'hookmask'
<span class="lineNum">      77 </span>            : ** is an atomic value. We assume that pointers are atomic too (e.g., gcc
<span class="lineNum">      78 </span>            : ** ensures that for all platforms where it runs). Moreover, 'hook' is
<span class="lineNum">      79 </span>            : ** always checked before being called (see 'luaD_hook').
<span class="lineNum">      80 </span>            : */
<span class="lineNum">      81 </span><span class="lineCov">          2 : LUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {</span>
<span class="lineNum">      82 </span><span class="lineCov">          2 :   if (func == NULL || mask == 0) {  /* turn off hooks? */</span>
<span class="lineNum">      83 </span><span class="lineCov">          1 :     mask = 0;</span>
<span class="lineNum">      84 </span><span class="lineCov">          1 :     func = NULL;</span>
<span class="lineNum">      85 </span>            :   }
<span class="lineNum">      86 </span><span class="lineCov">          2 :   if (isLua(L-&gt;ci))</span>
<span class="lineNum">      87 </span><span class="lineNoCov">          0 :     L-&gt;oldpc = L-&gt;ci-&gt;u.l.savedpc;</span>
<span class="lineNum">      88 </span><span class="lineCov">          2 :   L-&gt;hook = func;</span>
<span class="lineNum">      89 </span><span class="lineCov">          2 :   L-&gt;basehookcount = count;</span>
<span class="lineNum">      90 </span><span class="lineCov">          2 :   resethookcount(L);</span>
<span class="lineNum">      91 </span><span class="lineCov">          2 :   L-&gt;hookmask = cast_byte(mask);</span>
<span class="lineNum">      92 </span><span class="lineCov">          2 : }</span>
<span class="lineNum">      93 </span>            : 
<span class="lineNum">      94 </span>            : 
<span class="lineNum">      95 </span><span class="lineCov">          3 : LUA_API lua_Hook lua_gethook (lua_State *L) {</span>
<span class="lineNum">      96 </span><span class="lineCov">          3 :   return L-&gt;hook;</span>
<span class="lineNum">      97 </span>            : }
<span class="lineNum">      98 </span>            : 
<span class="lineNum">      99 </span>            : 
<span class="lineNum">     100 </span><span class="lineCov">          3 : LUA_API int lua_gethookmask (lua_State *L) {</span>
<span class="lineNum">     101 </span><span class="lineCov">          3 :   return L-&gt;hookmask;</span>
<span class="lineNum">     102 </span>            : }
<span class="lineNum">     103 </span>            : 
<span class="lineNum">     104 </span>            : 
<span class="lineNum">     105 </span><span class="lineCov">          3 : LUA_API int lua_gethookcount (lua_State *L) {</span>
<span class="lineNum">     106 </span><span class="lineCov">          3 :   return L-&gt;basehookcount;</span>
<span class="lineNum">     107 </span>            : }
<span class="lineNum">     108 </span>            : 
<span class="lineNum">     109 </span>            : 
<span class="lineNum">     110 </span><span class="lineCov">        300 : LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {</span>
<span class="lineNum">     111 </span>            :   int status;
<span class="lineNum">     112 </span>            :   CallInfo *ci;
<span class="lineNum">     113 </span><span class="lineCov">        300 :   if (level &lt; 0) return 0;  /* invalid (negative) level */</span>
<span class="lineNum">     114 </span>            :   lua_lock(L);
<span class="lineNum">     115 </span><span class="lineCov">        617 :   for (ci = L-&gt;ci; level &gt; 0 &amp;&amp; ci != &amp;L-&gt;base_ci; ci = ci-&gt;previous)</span>
<span class="lineNum">     116 </span><span class="lineCov">        317 :     level--;</span>
<span class="lineNum">     117 </span><span class="lineCov">        300 :   if (level == 0 &amp;&amp; ci != &amp;L-&gt;base_ci) {  /* level found? */</span>
<span class="lineNum">     118 </span><span class="lineCov">        277 :     status = 1;</span>
<span class="lineNum">     119 </span><span class="lineCov">        277 :     ar-&gt;i_ci = ci;</span>
<span class="lineNum">     120 </span>            :   }
<span class="lineNum">     121 </span><span class="lineCov">         23 :   else status = 0;  /* no such level */</span>
<span class="lineNum">     122 </span>            :   lua_unlock(L);
<span class="lineNum">     123 </span><span class="lineCov">        300 :   return status;</span>
<span class="lineNum">     124 </span>            : }
<span class="lineNum">     125 </span>            : 
<span class="lineNum">     126 </span>            : 
<span class="lineNum">     127 </span><span class="lineCov">         92 : static const char *upvalname (Proto *p, int uv) {</span>
<span class="lineNum">     128 </span><span class="lineCov">         92 :   TString *s = check_exp(uv &lt; p-&gt;sizeupvalues, p-&gt;upvalues[uv].name);</span>
<span class="lineNum">     129 </span><span class="lineCov">         92 :   if (s == NULL) return &quot;?&quot;;</span>
<span class="lineNum">     130 </span><span class="lineCov">         92 :   else return getstr(s);</span>
<span class="lineNum">     131 </span>            : }
<span class="lineNum">     132 </span>            : 
<span class="lineNum">     133 </span>            : 
<span class="lineNum">     134 </span><span class="lineNoCov">          0 : static const char *findvararg (CallInfo *ci, int n, StkId *pos) {</span>
<span class="lineNum">     135 </span><span class="lineNoCov">          0 :   int nparams = clLvalue(ci-&gt;func)-&gt;p-&gt;numparams;</span>
<span class="lineNum">     136 </span><span class="lineNoCov">          0 :   if (n &gt;= cast_int(ci-&gt;u.l.base - ci-&gt;func) - nparams)</span>
<span class="lineNum">     137 </span><span class="lineNoCov">          0 :     return NULL;  /* no such vararg */</span>
<span class="lineNum">     138 </span>            :   else {
<span class="lineNum">     139 </span><span class="lineNoCov">          0 :     *pos = ci-&gt;func + nparams + n;</span>
<span class="lineNum">     140 </span><span class="lineNoCov">          0 :     return &quot;(*vararg)&quot;;  /* generic name for any vararg */</span>
<span class="lineNum">     141 </span>            :   }
<span class="lineNum">     142 </span>            : }
<span class="lineNum">     143 </span>            : 
<span class="lineNum">     144 </span>            : 
<span class="lineNum">     145 </span><span class="lineCov">          3 : static const char *findlocal (lua_State *L, CallInfo *ci, int n,</span>
<span class="lineNum">     146 </span>            :                               StkId *pos) {
<span class="lineNum">     147 </span><span class="lineCov">          3 :   const char *name = NULL;</span>
<span class="lineNum">     148 </span>            :   StkId base;
<span class="lineNum">     149 </span><span class="lineCov">          3 :   if (isLua(ci)) {</span>
<span class="lineNum">     150 </span><span class="lineNoCov">          0 :     if (n &lt; 0)  /* access to vararg values? */</span>
<span class="lineNum">     151 </span><span class="lineNoCov">          0 :       return findvararg(ci, -n, pos);</span>
<span class="lineNum">     152 </span>            :     else {
<span class="lineNum">     153 </span><span class="lineNoCov">          0 :       base = ci-&gt;u.l.base;</span>
<span class="lineNum">     154 </span><span class="lineNoCov">          0 :       name = luaF_getlocalname(ci_func(ci)-&gt;p, n, currentpc(ci));</span>
<span class="lineNum">     155 </span>            :     }
<span class="lineNum">     156 </span>            :   }
<span class="lineNum">     157 </span>            :   else
<span class="lineNum">     158 </span><span class="lineCov">          3 :     base = ci-&gt;func + 1;</span>
<span class="lineNum">     159 </span><span class="lineCov">          3 :   if (name == NULL) {  /* no 'standard' name? */</span>
<span class="lineNum">     160 </span><span class="lineCov">          3 :     StkId limit = (ci == L-&gt;ci) ? L-&gt;top : ci-&gt;next-&gt;func;</span>
<span class="lineNum">     161 </span><span class="lineCov">          3 :     if (limit - base &gt;= n &amp;&amp; n &gt; 0)  /* is 'n' inside 'ci' stack? */</span>
<span class="lineNum">     162 </span><span class="lineCov">          2 :       name = &quot;(*temporary)&quot;;  /* generic name for any valid slot */</span>
<span class="lineNum">     163 </span>            :     else
<span class="lineNum">     164 </span><span class="lineCov">          1 :       return NULL;  /* no name */</span>
<span class="lineNum">     165 </span>            :   }
<span class="lineNum">     166 </span><span class="lineCov">          2 :   *pos = base + (n - 1);</span>
<span class="lineNum">     167 </span><span class="lineCov">          2 :   return name;</span>
<span class="lineNum">     168 </span>            : }
<span class="lineNum">     169 </span>            : 
<span class="lineNum">     170 </span>            : 
<span class="lineNum">     171 </span><span class="lineCov">          2 : LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {</span>
<span class="lineNum">     172 </span>            :   const char *name;
<span class="lineNum">     173 </span>            :   lua_lock(L);
<span class="lineNum">     174 </span><span class="lineCov">          2 :   swapextra(L);</span>
<span class="lineNum">     175 </span><span class="lineCov">          2 :   if (ar == NULL) {  /* information about non-active function? */</span>
<span class="lineNum">     176 </span><span class="lineCov">          1 :     if (!isLfunction(L-&gt;top - 1))  /* not a Lua function? */</span>
<span class="lineNum">     177 </span><span class="lineNoCov">          0 :       name = NULL;</span>
<span class="lineNum">     178 </span>            :     else  /* consider live variables at function start (parameters) */
<span class="lineNum">     179 </span><span class="lineCov">          1 :       name = luaF_getlocalname(clLvalue(L-&gt;top - 1)-&gt;p, n, 0);</span>
<span class="lineNum">     180 </span>            :   }
<span class="lineNum">     181 </span>            :   else {  /* active function; get information through 'ar' */
<span class="lineNum">     182 </span><span class="lineCov">          1 :     StkId pos = NULL;  /* to avoid warnings */</span>
<span class="lineNum">     183 </span><span class="lineCov">          1 :     name = findlocal(L, ar-&gt;i_ci, n, &amp;pos);</span>
<span class="lineNum">     184 </span><span class="lineCov">          1 :     if (name) {</span>
<span class="lineNum">     185 </span><span class="lineCov">          1 :       setobj2s(L, L-&gt;top, pos);</span>
<span class="lineNum">     186 </span><span class="lineCov">          1 :       api_incr_top(L);</span>
<span class="lineNum">     187 </span>            :     }
<span class="lineNum">     188 </span>            :   }
<span class="lineNum">     189 </span><span class="lineCov">          2 :   swapextra(L);</span>
<span class="lineNum">     190 </span>            :   lua_unlock(L);
<span class="lineNum">     191 </span><span class="lineCov">          2 :   return name;</span>
<span class="lineNum">     192 </span>            : }
<span class="lineNum">     193 </span>            : 
<span class="lineNum">     194 </span>            : 
<span class="lineNum">     195 </span><span class="lineCov">          2 : LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {</span>
<span class="lineNum">     196 </span><span class="lineCov">          2 :   StkId pos = NULL;  /* to avoid warnings */</span>
<span class="lineNum">     197 </span>            :   const char *name;
<span class="lineNum">     198 </span>            :   lua_lock(L);
<span class="lineNum">     199 </span><span class="lineCov">          2 :   swapextra(L);</span>
<span class="lineNum">     200 </span><span class="lineCov">          2 :   name = findlocal(L, ar-&gt;i_ci, n, &amp;pos);</span>
<span class="lineNum">     201 </span><span class="lineCov">          2 :   if (name) {</span>
<span class="lineNum">     202 </span><span class="lineCov">          1 :     setobjs2s(L, pos, L-&gt;top - 1);</span>
<span class="lineNum">     203 </span><span class="lineCov">          1 :     L-&gt;top--;  /* pop value */</span>
<span class="lineNum">     204 </span>            :   }
<span class="lineNum">     205 </span><span class="lineCov">          2 :   swapextra(L);</span>
<span class="lineNum">     206 </span>            :   lua_unlock(L);
<span class="lineNum">     207 </span><span class="lineCov">          2 :   return name;</span>
<span class="lineNum">     208 </span>            : }
<span class="lineNum">     209 </span>            : 
<span class="lineNum">     210 </span>            : 
<span class="lineNum">     211 </span><span class="lineCov">        190 : static void funcinfo (lua_Debug *ar, Closure *cl) {</span>
<span class="lineNum">     212 </span><span class="lineCov">        190 :   if (noLuaClosure(cl)) {</span>
<span class="lineNum">     213 </span><span class="lineCov">         65 :     ar-&gt;source = &quot;=[C]&quot;;</span>
<span class="lineNum">     214 </span><span class="lineCov">         65 :     ar-&gt;linedefined = -1;</span>
<span class="lineNum">     215 </span><span class="lineCov">         65 :     ar-&gt;lastlinedefined = -1;</span>
<span class="lineNum">     216 </span><span class="lineCov">         65 :     ar-&gt;what = &quot;C&quot;;</span>
<span class="lineNum">     217 </span>            :   }
<span class="lineNum">     218 </span>            :   else {
<span class="lineNum">     219 </span><span class="lineCov">        125 :     Proto *p = cl-&gt;l.p;</span>
<span class="lineNum">     220 </span><span class="lineCov">        125 :     ar-&gt;source = p-&gt;source ? getstr(p-&gt;source) : &quot;=?&quot;;</span>
<span class="lineNum">     221 </span><span class="lineCov">        125 :     ar-&gt;linedefined = p-&gt;linedefined;</span>
<span class="lineNum">     222 </span><span class="lineCov">        125 :     ar-&gt;lastlinedefined = p-&gt;lastlinedefined;</span>
<span class="lineNum">     223 </span><span class="lineCov">        125 :     ar-&gt;what = (ar-&gt;linedefined == 0) ? &quot;main&quot; : &quot;Lua&quot;;</span>
<span class="lineNum">     224 </span>            :   }
<span class="lineNum">     225 </span><span class="lineCov">        190 :   luaO_chunkid(ar-&gt;short_src, ar-&gt;source, LUA_IDSIZE);</span>
<span class="lineNum">     226 </span><span class="lineCov">        190 : }</span>
<span class="lineNum">     227 </span>            : 
<span class="lineNum">     228 </span>            : 
<span class="lineNum">     229 </span><span class="lineCov">          1 : static void collectvalidlines (lua_State *L, Closure *f) {</span>
<span class="lineNum">     230 </span><span class="lineCov">          1 :   if (noLuaClosure(f)) {</span>
<span class="lineNum">     231 </span><span class="lineNoCov">          0 :     setnilvalue(L-&gt;top);</span>
<span class="lineNum">     232 </span><span class="lineNoCov">          0 :     api_incr_top(L);</span>
<span class="lineNum">     233 </span>            :   }
<span class="lineNum">     234 </span>            :   else {
<span class="lineNum">     235 </span>            :     int i;
<span class="lineNum">     236 </span>            :     TValue v;
<span class="lineNum">     237 </span><span class="lineCov">          1 :     int *lineinfo = f-&gt;l.p-&gt;lineinfo;</span>
<span class="lineNum">     238 </span><span class="lineCov">          1 :     Table *t = luaH_new(L);  /* new table to store active lines */</span>
<span class="lineNum">     239 </span><span class="lineCov">          1 :     sethvalue(L, L-&gt;top, t);  /* push it on stack */</span>
<span class="lineNum">     240 </span><span class="lineCov">          1 :     api_incr_top(L);</span>
<span class="lineNum">     241 </span><span class="lineCov">          1 :     setbvalue(&amp;v, 1);  /* boolean 'true' to be the value of all indices */</span>
<span class="lineNum">     242 </span><span class="lineCov">         26 :     for (i = 0; i &lt; f-&gt;l.p-&gt;sizelineinfo; i++)  /* for all lines with code */</span>
<span class="lineNum">     243 </span><span class="lineCov">         25 :       luaH_setint(L, t, lineinfo[i], &amp;v);  /* table[line] = true */</span>
<span class="lineNum">     244 </span>            :   }
<span class="lineNum">     245 </span><span class="lineCov">          1 : }</span>
<span class="lineNum">     246 </span>            : 
<span class="lineNum">     247 </span>            : 
<span class="lineNum">     248 </span><span class="lineCov">         83 : static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {</span>
<span class="lineNum">     249 </span><span class="lineCov">         83 :   if (ci == NULL)  /* no 'ci'? */</span>
<span class="lineNum">     250 </span><span class="lineCov">          1 :     return NULL;  /* no info */</span>
<span class="lineNum">     251 </span><span class="lineCov">         82 :   else if (ci-&gt;callstatus &amp; CIST_FIN) {  /* is this a finalizer? */</span>
<span class="lineNum">     252 </span><span class="lineNoCov">          0 :     *name = &quot;__gc&quot;;</span>
<span class="lineNum">     253 </span><span class="lineNoCov">          0 :     return &quot;metamethod&quot;;  /* report it as such */</span>
<span class="lineNum">     254 </span>            :   }
<span class="lineNum">     255 </span>            :   /* calling function is a known Lua function? */
<span class="lineNum">     256 </span><span class="lineCov">         82 :   else if (!(ci-&gt;callstatus &amp; CIST_TAIL) &amp;&amp; isLua(ci-&gt;previous))</span>
<span class="lineNum">     257 </span><span class="lineCov">         66 :     return funcnamefromcode(L, ci-&gt;previous, name);</span>
<span class="lineNum">     258 </span><span class="lineCov">         16 :   else return NULL;  /* no way to find a name */</span>
<span class="lineNum">     259 </span>            : }
<span class="lineNum">     260 </span>            : 
<span class="lineNum">     261 </span>            : 
<span class="lineNum">     262 </span><span class="lineCov">        274 : static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,</span>
<span class="lineNum">     263 </span>            :                        Closure *f, CallInfo *ci) {
<span class="lineNum">     264 </span><span class="lineCov">        274 :   int status = 1;</span>
<span class="lineNum">     265 </span><span class="lineCov">        780 :   for (; *what; what++) {</span>
<span class="lineNum">     266 </span><span class="lineCov">        506 :     switch (*what) {</span>
<span class="lineNum">     267 </span><span class="lineCov">        190 :       case 'S': {</span>
<span class="lineNum">     268 </span><span class="lineCov">        190 :         funcinfo(ar, f);</span>
<span class="lineNum">     269 </span><span class="lineCov">        190 :         break;</span>
<span class="lineNum">     270 </span>            :       }
<span class="lineNum">     271 </span><span class="lineCov">        190 :       case 'l': {</span>
<span class="lineNum">     272 </span><span class="lineCov">        190 :         ar-&gt;currentline = (ci &amp;&amp; isLua(ci)) ? currentline(ci) : -1;</span>
<span class="lineNum">     273 </span><span class="lineCov">        190 :         break;</span>
<span class="lineNum">     274 </span>            :       }
<span class="lineNum">     275 </span><span class="lineCov">          2 :       case 'u': {</span>
<span class="lineNum">     276 </span><span class="lineCov">          2 :         ar-&gt;nups = (f == NULL) ? 0 : f-&gt;c.nupvalues;</span>
<span class="lineNum">     277 </span><span class="lineCov">          2 :         if (noLuaClosure(f)) {</span>
<span class="lineNum">     278 </span><span class="lineNoCov">          0 :           ar-&gt;isvararg = 1;</span>
<span class="lineNum">     279 </span><span class="lineNoCov">          0 :           ar-&gt;nparams = 0;</span>
<span class="lineNum">     280 </span>            :         }
<span class="lineNum">     281 </span>            :         else {
<span class="lineNum">     282 </span><span class="lineCov">          2 :           ar-&gt;isvararg = f-&gt;l.p-&gt;is_vararg;</span>
<span class="lineNum">     283 </span><span class="lineCov">          2 :           ar-&gt;nparams = f-&gt;l.p-&gt;numparams;</span>
<span class="lineNum">     284 </span>            :         }
<span class="lineNum">     285 </span><span class="lineCov">          2 :         break;</span>
<span class="lineNum">     286 </span>            :       }
<span class="lineNum">     287 </span><span class="lineCov">         19 :       case 't': {</span>
<span class="lineNum">     288 </span><span class="lineCov">         19 :         ar-&gt;istailcall = (ci) ? ci-&gt;callstatus &amp; CIST_TAIL : 0;</span>
<span class="lineNum">     289 </span><span class="lineCov">         19 :         break;</span>
<span class="lineNum">     290 </span>            :       }
<span class="lineNum">     291 </span><span class="lineCov">         83 :       case 'n': {</span>
<span class="lineNum">     292 </span><span class="lineCov">         83 :         ar-&gt;namewhat = getfuncname(L, ci, &amp;ar-&gt;name);</span>
<span class="lineNum">     293 </span><span class="lineCov">         83 :         if (ar-&gt;namewhat == NULL) {</span>
<span class="lineNum">     294 </span><span class="lineCov">         17 :           ar-&gt;namewhat = &quot;&quot;;  /* not found */</span>
<span class="lineNum">     295 </span><span class="lineCov">         17 :           ar-&gt;name = NULL;</span>
<span class="lineNum">     296 </span>            :         }
<span class="lineNum">     297 </span><span class="lineCov">         83 :         break;</span>
<span class="lineNum">     298 </span>            :       }
<span class="lineNum">     299 </span><span class="lineCov">         21 :       case 'L':</span>
<span class="lineNum">     300 </span>            :       case 'f':  /* handled by lua_getinfo */
<span class="lineNum">     301 </span><span class="lineCov">         21 :         break;</span>
<span class="lineNum">     302 </span><span class="lineCov">          1 :       default: status = 0;  /* invalid option */</span>
<span class="lineNum">     303 </span>            :     }
<span class="lineNum">     304 </span>            :   }
<span class="lineNum">     305 </span><span class="lineCov">        274 :   return status;</span>
<span class="lineNum">     306 </span>            : }
<span class="lineNum">     307 </span>            : 
<span class="lineNum">     308 </span>            : 
<span class="lineNum">     309 </span><span class="lineCov">        274 : LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {</span>
<span class="lineNum">     310 </span>            :   int status;
<span class="lineNum">     311 </span>            :   Closure *cl;
<span class="lineNum">     312 </span>            :   CallInfo *ci;
<span class="lineNum">     313 </span>            :   StkId func;
<span class="lineNum">     314 </span>            :   lua_lock(L);
<span class="lineNum">     315 </span><span class="lineCov">        274 :   swapextra(L);</span>
<span class="lineNum">     316 </span><span class="lineCov">        274 :   if (*what == '&gt;') {</span>
<span class="lineNum">     317 </span><span class="lineCov">          3 :     ci = NULL;</span>
<span class="lineNum">     318 </span><span class="lineCov">          3 :     func = L-&gt;top - 1;</span>
<span class="lineNum">     319 </span>            :     api_check(L, ttisfunction(func), &quot;function expected&quot;);
<span class="lineNum">     320 </span><span class="lineCov">          3 :     what++;  /* skip the '&gt;' */</span>
<span class="lineNum">     321 </span><span class="lineCov">          3 :     L-&gt;top--;  /* pop function */</span>
<span class="lineNum">     322 </span>            :   }
<span class="lineNum">     323 </span>            :   else {
<span class="lineNum">     324 </span><span class="lineCov">        271 :     ci = ar-&gt;i_ci;</span>
<span class="lineNum">     325 </span><span class="lineCov">        271 :     func = ci-&gt;func;</span>
<span class="lineNum">     326 </span>            :     lua_assert(ttisfunction(ci-&gt;func));
<span class="lineNum">     327 </span>            :   }
<span class="lineNum">     328 </span><span class="lineCov">        274 :   cl = ttisclosure(func) ? clvalue(func) : NULL;</span>
<span class="lineNum">     329 </span><span class="lineCov">        274 :   status = auxgetinfo(L, what, ar, cl, ci);</span>
<span class="lineNum">     330 </span><span class="lineCov">        274 :   if (strchr(what, 'f')) {</span>
<span class="lineNum">     331 </span><span class="lineCov">         20 :     setobjs2s(L, L-&gt;top, func);</span>
<span class="lineNum">     332 </span><span class="lineCov">         20 :     api_incr_top(L);</span>
<span class="lineNum">     333 </span>            :   }
<span class="lineNum">     334 </span><span class="lineCov">        274 :   swapextra(L);  /* correct before option 'L', which can raise a mem. error */</span>
<span class="lineNum">     335 </span><span class="lineCov">        274 :   if (strchr(what, 'L'))</span>
<span class="lineNum">     336 </span><span class="lineCov">          1 :     collectvalidlines(L, cl);</span>
<span class="lineNum">     337 </span>            :   lua_unlock(L);
<span class="lineNum">     338 </span><span class="lineCov">        274 :   return status;</span>
<span class="lineNum">     339 </span>            : }
<span class="lineNum">     340 </span>            : 
<span class="lineNum">     341 </span>            : 
<span class="lineNum">     342 </span>            : /*
<span class="lineNum">     343 </span>            : ** {======================================================
<span class="lineNum">     344 </span>            : ** Symbolic Execution
<span class="lineNum">     345 </span>            : ** =======================================================
<span class="lineNum">     346 </span>            : */
<span class="lineNum">     347 </span>            : 
<span class="lineNum">     348 </span>            : static const char *getobjname (Proto *p, int lastpc, int reg,
<span class="lineNum">     349 </span>            :                                const char **name);
<span class="lineNum">     350 </span>            : 
<span class="lineNum">     351 </span>            : 
<span class="lineNum">     352 </span>            : /*
<span class="lineNum">     353 </span>            : ** find a &quot;name&quot; for the RK value 'c'
<span class="lineNum">     354 </span>            : */
<span class="lineNum">     355 </span><span class="lineCov">         66 : static void kname (Proto *p, int pc, int c, const char **name) {</span>
<span class="lineNum">     356 </span><span class="lineCov">         66 :   if (ISK(c)) {  /* is 'c' a constant? */</span>
<span class="lineNum">     357 </span><span class="lineCov">         66 :     TValue *kvalue = &amp;p-&gt;k[INDEXK(c)];</span>
<span class="lineNum">     358 </span><span class="lineCov">         66 :     if (ttisstring(kvalue)) {  /* literal constant? */</span>
<span class="lineNum">     359 </span><span class="lineCov">         66 :       *name = svalue(kvalue);  /* it is its own name */</span>
<span class="lineNum">     360 </span><span class="lineCov">         66 :       return;</span>
<span class="lineNum">     361 </span>            :     }
<span class="lineNum">     362 </span>            :     /* else no reasonable name found */
<span class="lineNum">     363 </span>            :   }
<span class="lineNum">     364 </span>            :   else {  /* 'c' is a register */
<span class="lineNum">     365 </span><span class="lineNoCov">          0 :     const char *what = getobjname(p, pc, c, name); /* search for 'c' */</span>
<span class="lineNum">     366 </span><span class="lineNoCov">          0 :     if (what &amp;&amp; *what == 'c') {  /* found a constant name? */</span>
<span class="lineNum">     367 </span><span class="lineNoCov">          0 :       return;  /* 'name' already filled */</span>
<span class="lineNum">     368 </span>            :     }
<span class="lineNum">     369 </span>            :     /* else no reasonable name found */
<span class="lineNum">     370 </span>            :   }
<span class="lineNum">     371 </span><span class="lineNoCov">          0 :   *name = &quot;?&quot;;  /* no reasonable name found */</span>
<span class="lineNum">     372 </span>            : }
<span class="lineNum">     373 </span>            : 
<span class="lineNum">     374 </span>            : 
<span class="lineNum">     375 </span><span class="lineCov">        476 : static int filterpc (int pc, int jmptarget) {</span>
<span class="lineNum">     376 </span><span class="lineCov">        476 :   if (pc &lt; jmptarget)  /* is code conditional (inside a jump)? */</span>
<span class="lineNum">     377 </span><span class="lineCov">        149 :     return -1;  /* cannot know who sets that register */</span>
<span class="lineNum">     378 </span><span class="lineCov">        327 :   else return pc;  /* current position sets that register */</span>
<span class="lineNum">     379 </span>            : }
<span class="lineNum">     380 </span>            : 
<span class="lineNum">     381 </span>            : 
<span class="lineNum">     382 </span>            : /*
<span class="lineNum">     383 </span>            : ** try to find last instruction before 'lastpc' that modified register 'reg'
<span class="lineNum">     384 </span>            : */
<span class="lineNum">     385 </span><span class="lineCov">        165 : static int findsetreg (Proto *p, int lastpc, int reg) {</span>
<span class="lineNum">     386 </span>            :   int pc;
<span class="lineNum">     387 </span><span class="lineCov">        165 :   int setreg = -1;  /* keep last instruction that changed 'reg' */</span>
<span class="lineNum">     388 </span><span class="lineCov">        165 :   int jmptarget = 0;  /* any code before this address is conditional */</span>
<span class="lineNum">     389 </span><span class="lineCov">       1422 :   for (pc = 0; pc &lt; lastpc; pc++) {</span>
<span class="lineNum">     390 </span><span class="lineCov">       1257 :     Instruction i = p-&gt;code[pc];</span>
<span class="lineNum">     391 </span><span class="lineCov">       1257 :     OpCode op = GET_OPCODE(i);</span>
<span class="lineNum">     392 </span><span class="lineCov">       1257 :     int a = GETARG_A(i);</span>
<span class="lineNum">     393 </span><span class="lineCov">       1257 :     switch (op) {</span>
<span class="lineNum">     394 </span><span class="lineCov">         13 :       case OP_LOADNIL: {</span>
<span class="lineNum">     395 </span><span class="lineCov">         13 :         int b = GETARG_B(i);</span>
<span class="lineNum">     396 </span><span class="lineCov">         13 :         if (a &lt;= reg &amp;&amp; reg &lt;= a + b)  /* set registers from 'a' to 'a+b' */</span>
<span class="lineNum">     397 </span><span class="lineCov">          5 :           setreg = filterpc(pc, jmptarget);</span>
<span class="lineNum">     398 </span><span class="lineCov">         13 :         break;</span>
<span class="lineNum">     399 </span>            :       }
<span class="lineNum">     400 </span><span class="lineNoCov">          0 :       case OP_TFORCALL: {</span>
<span class="lineNum">     401 </span><span class="lineNoCov">          0 :         if (reg &gt;= a + 2)  /* affect all regs above its base */</span>
<span class="lineNum">     402 </span><span class="lineNoCov">          0 :           setreg = filterpc(pc, jmptarget);</span>
<span class="lineNum">     403 </span><span class="lineNoCov">          0 :         break;</span>
<span class="lineNum">     404 </span>            :       }
<span class="lineNum">     405 </span><span class="lineCov">        205 :       case OP_CALL:</span>
<span class="lineNum">     406 </span>            :       case OP_TAILCALL: {
<span class="lineNum">     407 </span><span class="lineCov">        205 :         if (reg &gt;= a)  /* affect all registers above base */</span>
<span class="lineNum">     408 </span><span class="lineCov">        204 :           setreg = filterpc(pc, jmptarget);</span>
<span class="lineNum">     409 </span><span class="lineCov">        205 :         break;</span>
<span class="lineNum">     410 </span>            :       }
<span class="lineNum">     411 </span><span class="lineCov">         45 :       case OP_JMP: {</span>
<span class="lineNum">     412 </span><span class="lineCov">         45 :         int b = GETARG_sBx(i);</span>
<span class="lineNum">     413 </span><span class="lineCov">         45 :         int dest = pc + 1 + b;</span>
<span class="lineNum">     414 </span>            :         /* jump is forward and do not skip 'lastpc'? */
<span class="lineNum">     415 </span><span class="lineCov">         45 :         if (pc &lt; dest &amp;&amp; dest &lt;= lastpc) {</span>
<span class="lineNum">     416 </span><span class="lineCov">         45 :           if (dest &gt; jmptarget)</span>
<span class="lineNum">     417 </span><span class="lineCov">         36 :             jmptarget = dest;  /* update 'jmptarget' */</span>
<span class="lineNum">     418 </span>            :         }
<span class="lineNum">     419 </span><span class="lineCov">         45 :         break;</span>
<span class="lineNum">     420 </span>            :       }
<span class="lineNum">     421 </span><span class="lineCov">        994 :       default:</span>
<span class="lineNum">     422 </span><span class="lineCov">        994 :         if (testAMode(op) &amp;&amp; reg == a)  /* any instruction that set A */</span>
<span class="lineNum">     423 </span><span class="lineCov">        267 :           setreg = filterpc(pc, jmptarget);</span>
<span class="lineNum">     424 </span><span class="lineCov">        994 :         break;</span>
<span class="lineNum">     425 </span>            :     }
<span class="lineNum">     426 </span>            :   }
<span class="lineNum">     427 </span><span class="lineCov">        165 :   return setreg;</span>
<span class="lineNum">     428 </span>            : }
<span class="lineNum">     429 </span>            : 
<span class="lineNum">     430 </span>            : 
<span class="lineNum">     431 </span><span class="lineCov">        175 : static const char *getobjname (Proto *p, int lastpc, int reg,</span>
<span class="lineNum">     432 </span>            :                                const char **name) {
<span class="lineNum">     433 </span>            :   int pc;
<span class="lineNum">     434 </span><span class="lineCov">        175 :   *name = luaF_getlocalname(p, reg + 1, lastpc);</span>
<span class="lineNum">     435 </span><span class="lineCov">        175 :   if (*name)  /* is a local? */</span>
<span class="lineNum">     436 </span><span class="lineCov">         10 :     return &quot;local&quot;;</span>
<span class="lineNum">     437 </span>            :   /* else try symbolic execution */
<span class="lineNum">     438 </span><span class="lineCov">        165 :   pc = findsetreg(p, lastpc, reg);</span>
<span class="lineNum">     439 </span><span class="lineCov">        165 :   if (pc != -1) {  /* could find instruction? */</span>
<span class="lineNum">     440 </span><span class="lineCov">        165 :     Instruction i = p-&gt;code[pc];</span>
<span class="lineNum">     441 </span><span class="lineCov">        165 :     OpCode op = GET_OPCODE(i);</span>
<span class="lineNum">     442 </span><span class="lineCov">        165 :     switch (op) {</span>
<span class="lineNum">     443 </span><span class="lineNoCov">          0 :       case OP_MOVE: {</span>
<span class="lineNum">     444 </span><span class="lineNoCov">          0 :         int b = GETARG_B(i);  /* move from 'b' to 'a' */</span>
<span class="lineNum">     445 </span><span class="lineNoCov">          0 :         if (b &lt; GETARG_A(i))</span>
<span class="lineNum">     446 </span><span class="lineNoCov">          0 :           return getobjname(p, pc, b, name);  /* get name for 'b' */</span>
<span class="lineNum">     447 </span><span class="lineNoCov">          0 :         break;</span>
<span class="lineNum">     448 </span>            :       }
<span class="lineNum">     449 </span><span class="lineCov">         64 :       case OP_GETTABUP:</span>
<span class="lineNum">     450 </span>            :       case OP_GETTABLE: {
<span class="lineNum">     451 </span><span class="lineCov">         64 :         int k = GETARG_C(i);  /* key index */</span>
<span class="lineNum">     452 </span><span class="lineCov">         64 :         int t = GETARG_B(i);  /* table index */</span>
<span class="lineNum">     453 </span><span class="lineCov">         64 :         const char *vn = (op == OP_GETTABLE)  /* name of indexed variable */</span>
<span class="lineNum">     454 </span><span class="lineCov">         41 :                          ? luaF_getlocalname(p, t + 1, pc)</span>
<span class="lineNum">     455 </span><span class="lineCov">         64 :                          : upvalname(p, t);</span>
<span class="lineNum">     456 </span><span class="lineCov">         64 :         kname(p, pc, k, name);</span>
<span class="lineNum">     457 </span><span class="lineCov">         64 :         return (vn &amp;&amp; strcmp(vn, LUA_ENV) == 0) ? &quot;global&quot; : &quot;field&quot;;</span>
<span class="lineNum">     458 </span>            :       }
<span class="lineNum">     459 </span><span class="lineCov">         65 :       case OP_GETUPVAL: {</span>
<span class="lineNum">     460 </span><span class="lineCov">         65 :         *name = upvalname(p, GETARG_B(i));</span>
<span class="lineNum">     461 </span><span class="lineCov">         65 :         return &quot;upvalue&quot;;</span>
<span class="lineNum">     462 </span>            :       }
<span class="lineNum">     463 </span><span class="lineCov">          3 :       case OP_LOADK:</span>
<span class="lineNum">     464 </span>            :       case OP_LOADKX: {
<span class="lineNum">     465 </span><span class="lineCov">          6 :         int b = (op == OP_LOADK) ? GETARG_Bx(i)</span>
<span class="lineNum">     466 </span><span class="lineCov">          3 :                                  : GETARG_Ax(p-&gt;code[pc + 1]);</span>
<span class="lineNum">     467 </span><span class="lineCov">          3 :         if (ttisstring(&amp;p-&gt;k[b])) {</span>
<span class="lineNum">     468 </span><span class="lineCov">          2 :           *name = svalue(&amp;p-&gt;k[b]);</span>
<span class="lineNum">     469 </span><span class="lineCov">          2 :           return &quot;constant&quot;;</span>
<span class="lineNum">     470 </span>            :         }
<span class="lineNum">     471 </span><span class="lineCov">          1 :         break;</span>
<span class="lineNum">     472 </span>            :       }
<span class="lineNum">     473 </span><span class="lineCov">          2 :       case OP_SELF: {</span>
<span class="lineNum">     474 </span><span class="lineCov">          2 :         int k = GETARG_C(i);  /* key index */</span>
<span class="lineNum">     475 </span><span class="lineCov">          2 :         kname(p, pc, k, name);</span>
<span class="lineNum">     476 </span><span class="lineCov">          2 :         return &quot;method&quot;;</span>
<span class="lineNum">     477 </span>            :       }
<span class="lineNum">     478 </span><span class="lineCov">         31 :       default: break;  /* go through to return NULL */</span>
<span class="lineNum">     479 </span>            :     }
<span class="lineNum">     480 </span><span class="lineNoCov">          0 :   }</span>
<span class="lineNum">     481 </span><span class="lineCov">         32 :   return NULL;  /* could not find reasonable name */</span>
<span class="lineNum">     482 </span>            : }
<span class="lineNum">     483 </span>            : 
<span class="lineNum">     484 </span>            : 
<span class="lineNum">     485 </span>            : /*
<span class="lineNum">     486 </span>            : ** Try to find a name for a function based on the code that called it.
<span class="lineNum">     487 </span>            : ** (Only works when function was called by a Lua function.)
<span class="lineNum">     488 </span>            : ** Returns what the name is (e.g., &quot;for iterator&quot;, &quot;method&quot;,
<span class="lineNum">     489 </span>            : ** &quot;metamethod&quot;) and sets '*name' to point to the name.
<span class="lineNum">     490 </span>            : */
<span class="lineNum">     491 </span><span class="lineCov">         66 : static const char *funcnamefromcode (lua_State *L, CallInfo *ci,</span>
<span class="lineNum">     492 </span>            :                                      const char **name) {
<span class="lineNum">     493 </span><span class="lineCov">         66 :   TMS tm = (TMS)0;  /* (initial value avoids warnings) */</span>
<span class="lineNum">     494 </span><span class="lineCov">         66 :   Proto *p = ci_func(ci)-&gt;p;  /* calling function */</span>
<span class="lineNum">     495 </span><span class="lineCov">         66 :   int pc = currentpc(ci);  /* calling instruction index */</span>
<span class="lineNum">     496 </span><span class="lineCov">         66 :   Instruction i = p-&gt;code[pc];  /* calling instruction */</span>
<span class="lineNum">     497 </span><span class="lineCov">         66 :   if (ci-&gt;callstatus &amp; CIST_HOOKED) {  /* was it called inside a hook? */</span>
<span class="lineNum">     498 </span><span class="lineNoCov">          0 :     *name = &quot;?&quot;;</span>
<span class="lineNum">     499 </span><span class="lineNoCov">          0 :     return &quot;hook&quot;;</span>
<span class="lineNum">     500 </span>            :   }
<span class="lineNum">     501 </span><span class="lineCov">         66 :   switch (GET_OPCODE(i)) {</span>
<span class="lineNum">     502 </span><span class="lineCov">         66 :     case OP_CALL:</span>
<span class="lineNum">     503 </span>            :     case OP_TAILCALL:
<span class="lineNum">     504 </span><span class="lineCov">         66 :       return getobjname(p, pc, GETARG_A(i), name);  /* get function name */</span>
<span class="lineNum">     505 </span><span class="lineNoCov">          0 :     case OP_TFORCALL: {  /* for iterator */</span>
<span class="lineNum">     506 </span><span class="lineNoCov">          0 :       *name = &quot;for iterator&quot;;</span>
<span class="lineNum">     507 </span><span class="lineNoCov">          0 :        return &quot;for iterator&quot;;</span>
<span class="lineNum">     508 </span>            :     }
<span class="lineNum">     509 </span>            :     /* other instructions can do calls through metamethods */
<span class="lineNum">     510 </span><span class="lineNoCov">          0 :     case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:</span>
<span class="lineNum">     511 </span><span class="lineNoCov">          0 :       tm = TM_INDEX;</span>
<span class="lineNum">     512 </span><span class="lineNoCov">          0 :       break;</span>
<span class="lineNum">     513 </span><span class="lineNoCov">          0 :     case OP_SETTABUP: case OP_SETTABLE:</span>
<span class="lineNum">     514 </span><span class="lineNoCov">          0 :       tm = TM_NEWINDEX;</span>
<span class="lineNum">     515 </span><span class="lineNoCov">          0 :       break;</span>
<span class="lineNum">     516 </span><span class="lineNoCov">          0 :     case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:</span>
<span class="lineNum">     517 </span>            :     case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND:
<span class="lineNum">     518 </span>            :     case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: {
<span class="lineNum">     519 </span><span class="lineNoCov">          0 :       int offset = cast_int(GET_OPCODE(i)) - cast_int(OP_ADD);  /* ORDER OP */</span>
<span class="lineNum">     520 </span><span class="lineNoCov">          0 :       tm = cast(TMS, offset + cast_int(TM_ADD));  /* ORDER TM */</span>
<span class="lineNum">     521 </span><span class="lineNoCov">          0 :       break;</span>
<span class="lineNum">     522 </span>            :     }
<span class="lineNum">     523 </span><span class="lineNoCov">          0 :     case OP_UNM: tm = TM_UNM; break;</span>
<span class="lineNum">     524 </span><span class="lineNoCov">          0 :     case OP_BNOT: tm = TM_BNOT; break;</span>
<span class="lineNum">     525 </span><span class="lineNoCov">          0 :     case OP_LEN: tm = TM_LEN; break;</span>
<span class="lineNum">     526 </span><span class="lineNoCov">          0 :     case OP_CONCAT: tm = TM_CONCAT; break;</span>
<span class="lineNum">     527 </span><span class="lineNoCov">          0 :     case OP_EQ: tm = TM_EQ; break;</span>
<span class="lineNum">     528 </span><span class="lineNoCov">          0 :     case OP_LT: tm = TM_LT; break;</span>
<span class="lineNum">     529 </span><span class="lineNoCov">          0 :     case OP_LE: tm = TM_LE; break;</span>
<span class="lineNum">     530 </span><span class="lineNoCov">          0 :     default:</span>
<span class="lineNum">     531 </span><span class="lineNoCov">          0 :       return NULL;  /* cannot find a reasonable name */</span>
<span class="lineNum">     532 </span>            :   }
<span class="lineNum">     533 </span><span class="lineNoCov">          0 :   *name = getstr(G(L)-&gt;tmname[tm]);</span>
<span class="lineNum">     534 </span><span class="lineNoCov">          0 :   return &quot;metamethod&quot;;</span>
<span class="lineNum">     535 </span>            : }
<span class="lineNum">     536 </span>            : 
<span class="lineNum">     537 </span>            : /* }====================================================== */
<span class="lineNum">     538 </span>            : 
<span class="lineNum">     539 </span>            : 
<span class="lineNum">     540 </span>            : 
<span class="lineNum">     541 </span>            : /*
<span class="lineNum">     542 </span>            : ** The subtraction of two potentially unrelated pointers is
<span class="lineNum">     543 </span>            : ** not ISO C, but it should not crash a program; the subsequent
<span class="lineNum">     544 </span>            : ** checks are ISO C and ensure a correct result.
<span class="lineNum">     545 </span>            : */
<span class="lineNum">     546 </span><span class="lineCov">        189 : static int isinstack (CallInfo *ci, const TValue *o) {</span>
<span class="lineNum">     547 </span><span class="lineCov">        189 :   ptrdiff_t i = o - ci-&gt;u.l.base;</span>
<span class="lineNum">     548 </span><span class="lineCov">        189 :   return (0 &lt;= i &amp;&amp; i &lt; (ci-&gt;top - ci-&gt;u.l.base) &amp;&amp; ci-&gt;u.l.base + i == o);</span>
<span class="lineNum">     549 </span>            : }
<span class="lineNum">     550 </span>            : 
<span class="lineNum">     551 </span>            : 
<span class="lineNum">     552 </span>            : /*
<span class="lineNum">     553 </span>            : ** Checks whether value 'o' came from an upvalue. (That can only happen
<span class="lineNum">     554 </span>            : ** with instructions OP_GETTABUP/OP_SETTABUP, which operate directly on
<span class="lineNum">     555 </span>            : ** upvalues.)
<span class="lineNum">     556 </span>            : */
<span class="lineNum">     557 </span><span class="lineCov">        193 : static const char *getupvalname (CallInfo *ci, const TValue *o,</span>
<span class="lineNum">     558 </span>            :                                  const char **name) {
<span class="lineNum">     559 </span><span class="lineCov">        193 :   LClosure *c = ci_func(ci);</span>
<span class="lineNum">     560 </span>            :   int i;
<span class="lineNum">     561 </span><span class="lineCov">        278 :   for (i = 0; i &lt; c-&gt;nupvalues; i++) {</span>
<span class="lineNum">     562 </span><span class="lineCov">         89 :     if (c-&gt;upvals[i]-&gt;v == o) {</span>
<span class="lineNum">     563 </span><span class="lineCov">          4 :       *name = upvalname(c-&gt;p, i);</span>
<span class="lineNum">     564 </span><span class="lineCov">          4 :       return &quot;upvalue&quot;;</span>
<span class="lineNum">     565 </span>            :     }
<span class="lineNum">     566 </span>            :   }
<span class="lineNum">     567 </span><span class="lineCov">        189 :   return NULL;</span>
<span class="lineNum">     568 </span>            : }
<span class="lineNum">     569 </span>            : 
<span class="lineNum">     570 </span>            : 
<span class="lineNum">     571 </span><span class="lineCov">        195 : static const char *varinfo (lua_State *L, const TValue *o) {</span>
<span class="lineNum">     572 </span><span class="lineCov">        195 :   const char *name = NULL;  /* to avoid warnings */</span>
<span class="lineNum">     573 </span><span class="lineCov">        195 :   CallInfo *ci = L-&gt;ci;</span>
<span class="lineNum">     574 </span><span class="lineCov">        195 :   const char *kind = NULL;</span>
<span class="lineNum">     575 </span><span class="lineCov">        195 :   if (isLua(ci)) {</span>
<span class="lineNum">     576 </span><span class="lineCov">        193 :     kind = getupvalname(ci, o, &amp;name);  /* check whether 'o' is an upvalue */</span>
<span class="lineNum">     577 </span><span class="lineCov">        193 :     if (!kind &amp;&amp; isinstack(ci, o))  /* no? try a register */</span>
<span class="lineNum">     578 </span><span class="lineCov">        109 :       kind = getobjname(ci_func(ci)-&gt;p, currentpc(ci),</span>
<span class="lineNum">     579 </span><span class="lineCov">        109 :                         cast_int(o - ci-&gt;u.l.base), &amp;name);</span>
<span class="lineNum">     580 </span>            :   }
<span class="lineNum">     581 </span><span class="lineCov">        195 :   return (kind) ? luaO_pushfstring(L, &quot; (%s '%s')&quot;, kind, name) : &quot;&quot;;</span>
<span class="lineNum">     582 </span>            : }
<span class="lineNum">     583 </span>            : 
<span class="lineNum">     584 </span>            : 
<span class="lineNum">     585 </span><span class="lineCov">        184 : l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {</span>
<span class="lineNum">     586 </span><span class="lineCov">        184 :   const char *t = luaT_objtypename(L, o);</span>
<span class="lineNum">     587 </span><span class="lineCov">        184 :   luaG_runerror(L, &quot;attempt to %s a %s value%s&quot;, op, t, varinfo(L, o));</span>
<span class="lineNum">     588 </span>            : }
<span class="lineNum">     589 </span>            : 
<span class="lineNum">     590 </span>            : 
<span class="lineNum">     591 </span><span class="lineCov">          9 : l_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) {</span>
<span class="lineNum">     592 </span><span class="lineCov">          9 :   if (ttisstring(p1) || cvt2str(p1)) p1 = p2;</span>
<span class="lineNum">     593 </span><span class="lineCov">          9 :   luaG_typeerror(L, p1, &quot;concatenate&quot;);</span>
<span class="lineNum">     594 </span>            : }
<span class="lineNum">     595 </span>            : 
<span class="lineNum">     596 </span>            : 
<span class="lineNum">     597 </span><span class="lineCov">        152 : l_noret luaG_opinterror (lua_State *L, const TValue *p1,</span>
<span class="lineNum">     598 </span>            :                          const TValue *p2, const char *msg) {
<span class="lineNum">     599 </span>            :   lua_Number temp;
<span class="lineNum">     600 </span><span class="lineCov">        152 :   if (!tonumber(p1, &amp;temp))  /* first operand is wrong? */</span>
<span class="lineNum">     601 </span><span class="lineCov">        101 :     p2 = p1;  /* now second is wrong */</span>
<span class="lineNum">     602 </span><span class="lineCov">        152 :   luaG_typeerror(L, p2, msg);</span>
<span class="lineNum">     603 </span>            : }
<span class="lineNum">     604 </span>            : 
<span class="lineNum">     605 </span>            : 
<span class="lineNum">     606 </span>            : /*
<span class="lineNum">     607 </span>            : ** Error when both values are convertible to numbers, but not to integers
<span class="lineNum">     608 </span>            : */
<span class="lineNum">     609 </span><span class="lineCov">         11 : l_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) {</span>
<span class="lineNum">     610 </span>            :   lua_Integer temp;
<span class="lineNum">     611 </span><span class="lineCov">         11 :   if (!tointeger(p1, &amp;temp))</span>
<span class="lineNum">     612 </span><span class="lineCov">          6 :     p2 = p1;</span>
<span class="lineNum">     613 </span><span class="lineCov">         11 :   luaG_runerror(L, &quot;number%s has no integer representation&quot;, varinfo(L, p2));</span>
<span class="lineNum">     614 </span>            : }
<span class="lineNum">     615 </span>            : 
<span class="lineNum">     616 </span>            : 
<span class="lineNum">     617 </span><span class="lineCov">         74 : l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {</span>
<span class="lineNum">     618 </span><span class="lineCov">         74 :   const char *t1 = luaT_objtypename(L, p1);</span>
<span class="lineNum">     619 </span><span class="lineCov">         74 :   const char *t2 = luaT_objtypename(L, p2);</span>
<span class="lineNum">     620 </span><span class="lineCov">         74 :   if (strcmp(t1, t2) == 0)</span>
<span class="lineNum">     621 </span><span class="lineCov">         28 :     luaG_runerror(L, &quot;attempt to compare two %s values&quot;, t1);</span>
<span class="lineNum">     622 </span>            :   else
<span class="lineNum">     623 </span><span class="lineCov">         46 :     luaG_runerror(L, &quot;attempt to compare %s with %s&quot;, t1, t2);</span>
<span class="lineNum">     624 </span>            : }
<span class="lineNum">     625 </span>            : 
<span class="lineNum">     626 </span>            : 
<span class="lineNum">     627 </span>            : /* add src:line information to 'msg' */
<span class="lineNum">     628 </span><span class="lineCov">        315 : const char *luaG_addinfo (lua_State *L, const char *msg, TString *src,</span>
<span class="lineNum">     629 </span>            :                                         int line) {
<span class="lineNum">     630 </span>            :   char buff[LUA_IDSIZE];
<span class="lineNum">     631 </span><span class="lineCov">        315 :   if (src)</span>
<span class="lineNum">     632 </span><span class="lineCov">        315 :     luaO_chunkid(buff, getstr(src), LUA_IDSIZE);</span>
<span class="lineNum">     633 </span>            :   else {  /* no source available; use &quot;?&quot; instead */
<span class="lineNum">     634 </span><span class="lineNoCov">          0 :     buff[0] = '?'; buff[1] = '\0';</span>
<span class="lineNum">     635 </span>            :   }
<span class="lineNum">     636 </span><span class="lineCov">        315 :   return luaO_pushfstring(L, &quot;%s:%d: %s&quot;, buff, line, msg);</span>
<span class="lineNum">     637 </span>            : }
<span class="lineNum">     638 </span>            : 
<span class="lineNum">     639 </span>            : 
<span class="lineNum">     640 </span><span class="lineCov">        460 : l_noret luaG_errormsg (lua_State *L) {</span>
<span class="lineNum">     641 </span><span class="lineCov">        460 :   if (L-&gt;errfunc != 0) {  /* is there an error handling function? */</span>
<span class="lineNum">     642 </span><span class="lineCov">         10 :     StkId errfunc = restorestack(L, L-&gt;errfunc);</span>
<span class="lineNum">     643 </span><span class="lineCov">         10 :     setobjs2s(L, L-&gt;top, L-&gt;top - 1);  /* move argument */</span>
<span class="lineNum">     644 </span><span class="lineCov">         10 :     setobjs2s(L, L-&gt;top - 1, errfunc);  /* push function */</span>
<span class="lineNum">     645 </span><span class="lineCov">         10 :     L-&gt;top++;  /* assume EXTRA_STACK */</span>
<span class="lineNum">     646 </span><span class="lineCov">         10 :     luaD_callnoyield(L, L-&gt;top - 2, 1);  /* call it */</span>
<span class="lineNum">     647 </span>            :   }
<span class="lineNum">     648 </span><span class="lineCov">        460 :   luaD_throw(L, LUA_ERRRUN);</span>
<span class="lineNum">     649 </span>            : }
<span class="lineNum">     650 </span>            : 
<span class="lineNum">     651 </span>            : 
<span class="lineNum">     652 </span><span class="lineCov">        279 : l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {</span>
<span class="lineNum">     653 </span><span class="lineCov">        279 :   CallInfo *ci = L-&gt;ci;</span>
<span class="lineNum">     654 </span>            :   const char *msg;
<span class="lineNum">     655 </span>            :   va_list argp;
<span class="lineNum">     656 </span><span class="lineCov">        279 :   luaC_checkGC(L);  /* error message uses memory */</span>
<span class="lineNum">     657 </span><span class="lineCov">        279 :   va_start(argp, fmt);</span>
<span class="lineNum">     658 </span><span class="lineCov">        279 :   msg = luaO_pushvfstring(L, fmt, argp);  /* format message */</span>
<span class="lineNum">     659 </span><span class="lineCov">        279 :   va_end(argp);</span>
<span class="lineNum">     660 </span><span class="lineCov">        279 :   if (isLua(ci))  /* if Lua function, add source:line information */</span>
<span class="lineNum">     661 </span><span class="lineCov">        274 :     luaG_addinfo(L, msg, ci_func(ci)-&gt;p-&gt;source, currentline(ci));</span>
<span class="lineNum">     662 </span><span class="lineCov">        279 :   luaG_errormsg(L);</span>
<span class="lineNum">     663 </span>            : }
<span class="lineNum">     664 </span>            : 
<span class="lineNum">     665 </span>            : 
<span class="lineNum">     666 </span><span class="lineCov">       1279 : void luaG_traceexec (lua_State *L) {</span>
<span class="lineNum">     667 </span><span class="lineCov">       1279 :   CallInfo *ci = L-&gt;ci;</span>
<span class="lineNum">     668 </span><span class="lineCov">       1279 :   lu_byte mask = L-&gt;hookmask;</span>
<span class="lineNum">     669 </span><span class="lineCov">       1279 :   int counthook = (--L-&gt;hookcount == 0 &amp;&amp; (mask &amp; LUA_MASKCOUNT));</span>
<span class="lineNum">     670 </span><span class="lineCov">       1279 :   if (counthook)</span>
<span class="lineNum">     671 </span><span class="lineCov">         30 :     resethookcount(L);  /* reset count */</span>
<span class="lineNum">     672 </span><span class="lineCov">       1249 :   else if (!(mask &amp; LUA_MASKLINE))</span>
<span class="lineNum">     673 </span><span class="lineCov">       1249 :     return;  /* no line hook and count != 0; nothing to be done */</span>
<span class="lineNum">     674 </span><span class="lineCov">         30 :   if (ci-&gt;callstatus &amp; CIST_HOOKYIELD) {  /* called hook last time? */</span>
<span class="lineNum">     675 </span><span class="lineNoCov">          0 :     ci-&gt;callstatus &amp;= ~CIST_HOOKYIELD;  /* erase mark */</span>
<span class="lineNum">     676 </span><span class="lineNoCov">          0 :     return;  /* do not call hook again (VM yielded, so it did not move) */</span>
<span class="lineNum">     677 </span>            :   }
<span class="lineNum">     678 </span><span class="lineCov">         30 :   if (counthook)</span>
<span class="lineNum">     679 </span><span class="lineCov">         30 :     luaD_hook(L, LUA_HOOKCOUNT, -1);  /* call count hook */</span>
<span class="lineNum">     680 </span><span class="lineCov">         30 :   if (mask &amp; LUA_MASKLINE) {</span>
<span class="lineNum">     681 </span><span class="lineNoCov">          0 :     Proto *p = ci_func(ci)-&gt;p;</span>
<span class="lineNum">     682 </span><span class="lineNoCov">          0 :     int npc = pcRel(ci-&gt;u.l.savedpc, p);</span>
<span class="lineNum">     683 </span><span class="lineNoCov">          0 :     int newline = getfuncline(p, npc);</span>
<span class="lineNum">     684 </span><span class="lineNoCov">          0 :     if (npc == 0 ||  /* call linehook when enter a new function, */</span>
<span class="lineNum">     685 </span><span class="lineNoCov">          0 :         ci-&gt;u.l.savedpc &lt;= L-&gt;oldpc ||  /* when jump back (loop), or when */</span>
<span class="lineNum">     686 </span><span class="lineNoCov">          0 :         newline != getfuncline(p, pcRel(L-&gt;oldpc, p)))  /* enter a new line */</span>
<span class="lineNum">     687 </span><span class="lineNoCov">          0 :       luaD_hook(L, LUA_HOOKLINE, newline);  /* call line hook */</span>
<span class="lineNum">     688 </span>            :   }
<span class="lineNum">     689 </span><span class="lineCov">         30 :   L-&gt;oldpc = ci-&gt;u.l.savedpc;</span>
<span class="lineNum">     690 </span><span class="lineCov">         30 :   if (L-&gt;status == LUA_YIELD) {  /* did hook yield? */</span>
<span class="lineNum">     691 </span><span class="lineNoCov">          0 :     if (counthook)</span>
<span class="lineNum">     692 </span><span class="lineNoCov">          0 :       L-&gt;hookcount = 1;  /* undo decrement to zero */</span>
<span class="lineNum">     693 </span><span class="lineNoCov">          0 :     ci-&gt;u.l.savedpc--;  /* undo increment (resume will increment it again) */</span>
<span class="lineNum">     694 </span><span class="lineNoCov">          0 :     ci-&gt;callstatus |= CIST_HOOKYIELD;  /* mark that it yielded */</span>
<span class="lineNum">     695 </span><span class="lineNoCov">          0 :     ci-&gt;func = L-&gt;top - 1;  /* protect stack below results */</span>
<span class="lineNum">     696 </span><span class="lineNoCov">          0 :     luaD_throw(L, LUA_YIELD);</span>
<span class="lineNum">     697 </span>            :   }
<span class="lineNum">     698 </span>            : }
<span class="lineNum">     699 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
